//
//  BJHomeListTableViewCell.m
//  BowJoy
//
//  Created by  on 2024/5/20.
//

#import "BJHomeListTableViewCell.h"

@implementation BJHomeListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setModel:(BJAnchorWallModelData *)model{
    if(model.avatar){
        [self.headerIcon sd_setImageWithURL:[NSURL URLWithString:model.avatar] completed:nil];
    }else{
        self.headerIcon.image = [UIImage imageNamed:@"ic_head_1"];
    }
    self.titleL.text = [self getLenghtStr:model.nickname withCount:12];
    self.contenL.text = [self getLenghtStr:model.content withCount:12];
    NSArray *imageArr = [model.imageArrStr componentsSeparatedByString:@","];

    if (imageArr.count>0){
        self.anchorImage.hidden = NO;
        self.anchorImage.image = [UIImage imageNamed:imageArr[0]];
    }else{
        self.anchorImage.hidden = YES;
    }
    
    if (imageArr.count>1){
        self.anchorImage1.hidden = NO;
        self.anchorImage1.image = [UIImage imageNamed:imageArr[1]];
    }else{
        self.anchorImage1.hidden = YES;
    }
    
    if (imageArr.count>2){
        self.anchorImage2.hidden = NO;
        self.anchorImage2.image = [UIImage imageNamed:imageArr[2]];
    }else{
        self.anchorImage2.hidden = YES;
    }
    

    self.chatNumL.text = [NSString stringWithFormat:@"%ld",model.commentNum ? model.commentNum:0];
    self.followIcon.image = model.isLike ? [UIImage imageNamed:@"icon_love_red"]:[UIImage imageNamed:@"icon_love_gray"];
    self.folloeNumL.text = [NSString stringWithFormat:@"%ld",model.followNum];
//    int randomNumber = 10 + arc4random_uniform(51);
//    self.pushTime.text = [NSString stringWithFormat:@"%dmin ago",randomNumber];

}

- (NSString *)getLenghtStr:(NSString *)str withCount:(NSInteger)count{
    NSString * str1 = str;
    if (str.length>count){
        NSRange range = [str rangeOfComposedCharacterSequenceAtIndex:count];
        NSString *subStr = [str substringToIndex:range.location];
        str1 = [NSString stringWithFormat:@"%@...",subStr];
    }
    
    return str1;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
